package main.ui.models.combo;

import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

import main.ui.models.combo.CountriesComboModel.Country;

public class CountryBoxRenderer extends DefaultListCellRenderer 
{
	private static final long serialVersionUID = 5240974204116744458L;

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) 
	{
		if (isSelected) 
		{
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} 
		else 
		{
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		if (value instanceof Country) 
		{
			Country country = (Country) value;
			setIcon(country.getIcon());
			setText(country.getValue());
		} 
		else 
		{
			setIcon(null);
			setText((value == null) ? "" : value.toString());
		}

		return this;
	}

}